<template>
    <!-- 在线审核页面。激活学生报道状态 -->
    <div class="table-stu">
        <el-table :data="tableData" style="width: 100%">
            <el-table-column label="序号" type="index" width="150px"> </el-table-column>
            <el-table-column label="学号" prop="id"> </el-table-column>
            <el-table-column label="姓名" prop="name"> </el-table-column>
            <el-table-column label="年龄" prop="age"> </el-table-column>
            <el-table-column label="学院" prop="college"> </el-table-column>
            <el-table-column label="身份证" prop="idCard"> </el-table-column>
            <el-table-column label="民族" prop="nation"> </el-table-column>
            <el-table-column label="籍贯" prop="province"> </el-table-column>
            <el-table-column label="角色" prop="role">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.role == 1">管理员</el-tag>
                    <el-tag type="info" v-if="scope.row.role == 0">学生</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="审核状态" prop="status">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.status == 1">已审核</el-tag>
                    <el-tag type="info" v-if="scope.row.status == 0">未审核</el-tag>
                </template>
            </el-table-column>
            <el-table-column align="right">
                <template slot-scope="scope">
                    <el-button size="mini" type="success" @click="stuExam(scope.$index, scope.row)">审核通过</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="block">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[5, 10, 20, 40]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="tableData.length"
            >
            </el-pagination>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            tableData: [],
            currentPage: 1,
            pageSize: 10
        };
    },
    methods: {
        // 学生审核
        async stuExam(index, row) {
            const res = await this.getJSON(`/student/exam?stuId=${row.id}&status=1`);
            if (res.code == 200) {
                this.$message.success('审核通过');
                this.stuList();
            } else {
                this.$message.error('审核失败');
            }
        },
        // 加载全部学生
        async stuList() {
            const res = await this.getJSON(`/student/findlist?current=${this.currentPage}&size=${this.pageSize}`);
            console.log(res);
            if (res.code == 200) {
                this.tableData = res.data.records;
            } else {
                this.$message.error('数据加载失败，请联系网站管理员');
            }
        },
        // 当前页
        handleSizeChange: function(size) {
            this.pagesize = size;
            console.log(this.pagesize); //每页下拉显示数据
        },
        handleCurrentChange: function(currentPage) {
            this.currentPage = currentPage;
            console.log(this.currentPage); //点击第几页
        }
    },
    created() {
        this.stuList();
    }
};
</script>
<style scoped>
.table-stu {
    margin: 5px;
}
</style>
